<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.*" %>
<%@ page import="au.com.somethingwritten.model.*" %>
	<%
           if (request.getParameter("fromMasterPage") == null)
           {
                %>
                  <jsp:forward page="masterPage.jsp">
                    <jsp:param name="embeddedPageName" value 
                     ="resultsPage.jsp"/>
                     <jsp:param name="submitPageName" value 
                     ="resultsPage.jsp"/>
                  </jsp:forward>
                <%
           }
      %>
      	<h2>Search Options</h2>
      	<form name="advanced_search" method="post" action="basicSearch">
			<select id="search_options" name="search_options" size=1>
				<option value="all">All</option>
				<option value="authors">Author</option>
				<option value="categories">Category</option>
				<option value="titles">Title</option>
				<option value="isbn">Isbn</option>
			</select>
			<input id="adv_search_input" type="text" name="search_text"/>
			<button id="adv_search_button" type="submit" name="adv_search_button">search</button>
		</form>
		<h2>Search Results</h2>
		<div class="result_holder">
		<%
  			ArrayList<Book> allBooks = (ArrayList<Book>)request.getAttribute("books");
			if(allBooks.size() < 1)
				out.print("<h3>No Results Found</h3>\n");
  			for(int i = 0; i < allBooks.size(); i++){
    			out.print("<div class=\"result_book\"> \n");
    			//create a link for the image.
    			out.print("<a href=\"/SomethingWritten/bookDetails?book=" + allBooks.get(i).getId().toString() + "\">\n");
    			//display image and set alt text 
    			out.print("<img src=\"" + allBooks.get(i).getImageFile() + "\" alt=\"" + allBooks.get(i).getTitle() + " Cover\" /> \n" );
    			//end link
    			out.print("</a>\n");
    			out.print("<div class=\"book_detail\"> \n");
    			//display title
    			out.print("<h3>" + allBooks.get(i).getTitle() + "</h3>");
    			//display author
    			out.print("by " + allBooks.get(i).getAuthor() + "<br />");
    			//display price
    			out.print("Price: $" + String.format("%1$,.2f", allBooks.get(i).getPrice()) + "<br /><br />");
    			//display quantity edit form
    			//display buy button
    			out.print("<form name=\"add_to_cart\" method=\"post\" action=\"addToCart?book_id=" + allBooks.get(i).getId().toString() + "&amp;quantity=1\">");
					out.print("<button class=\"addToCart\" type=\"submit\" name=\"addToCart\">Add to cart</button><br />");
				out.print("</form>");	
    			out.print("</div> \n");
    			out.print("<div class=\"float_clear\"></div> \n");
    			out.print("</div> \n");
  			}
		%>
		</div>